<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
  <title>Description of v_entropy</title>
  <meta name="keywords" content="v_entropy">
  <meta name="description" content="V_ENTROPY calculates the v_entropy of discrete and sampled continuous distributions H=(P,DIM,COND,ARG,STEP)">
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="generator" content="m2html &copy; 2003 Guillaume Flandin">
  <meta name="robots" content="index, follow">
  <link type="text/css" rel="stylesheet" href="../m2html.css">
</head>
<body>
<a name="_top"></a>
<div><a href="../index.html">Home</a> &gt;  <a href="index.html">v_mfiles</a> &gt; v_entropy.m</div>

<!--<table width="100%"><tr><td align="left"><a href="../index.html"><img alt="<" border="0" src="../left.png">&nbsp;Master index</a></td>
<td align="right"><a href="index.html">Index for v_mfiles&nbsp;<img alt=">" border="0" src="../right.png"></a></td></tr></table>-->

<h1>v_entropy
</h1>

<h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="box"><strong>V_ENTROPY calculates the v_entropy of discrete and sampled continuous distributions H=(P,DIM,COND,ARG,STEP)</strong></div>

<h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="box"><strong>function h=v_entropy(p,dim,cond,arg,step) </strong></div>

<h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="fragment"><pre class="comment">V_ENTROPY calculates the v_entropy of discrete and sampled continuous distributions H=(P,DIM,COND,ARG,STEP)

  Inputs:  P        is a vector or matrix of probabilities - one dimension per variable
           DIM      lists dimensions along which to evaluate the v_entropy [default: 1st non singleton dimension]
           COND     lists dimensions to use as conditional variables [default - none]
           ARG      lists dimensions to use as parameters in the ouput [default - none]
           STEP     for continuous distributions STEP gives the sample increment for each dimension of P
                    if STEP is a scalar, the increment is assumed to be the same for each dimension

 Outputs:  H        is the v_entropy. It will have the same number of dimensions as the length of the ARG input.
                    If the STEP argument is specified then this will be the differential v_entropy.

 Example: Suppose P(W,X,Y,Z) represents the joint probability of four correlated random variables

               (a) H(W,X,Y,Z) = v_entropy(P,[1 2 3 4]). 
               (b) H(W) = v_entropy(P), or equivalently v_entropy(P,1)
               (c) H(W,Z | X,Y) = v_entropy(P,[1 4],[2 3])
               (d) H(W | X, Z=z) = v_entropy(P,1,2,4); this is a function of z and will be a column vector

 As a special case, if the dimensions included in DIM are all singletons, the entries in P are treated
 as Bernoulli variable probabilities.</pre></div>

<!-- crossreference -->
<h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
This function calls:
<ul style="list-style-image:url(../matlabicon.gif)">
<li><a href="v_entropy.html" class="code" title="function h=v_entropy(p,dim,cond,arg,step)">v_entropy</a>	V_ENTROPY calculates the v_entropy of discrete and sampled continuous distributions H=(P,DIM,COND,ARG,STEP)</li></ul>
This function is called by:
<ul style="list-style-image:url(../matlabicon.gif)">
<li><a href="v_entropy.html" class="code" title="function h=v_entropy(p,dim,cond,arg,step)">v_entropy</a>	V_ENTROPY calculates the v_entropy of discrete and sampled continuous distributions H=(P,DIM,COND,ARG,STEP)</li></ul>
<!-- crossreference -->


<h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="fragment"><pre>0001 <a name="_sub0" href="#_subfunctions" class="code">function h=v_entropy(p,dim,cond,arg,step)</a>
0002 <span class="comment">%V_ENTROPY calculates the v_entropy of discrete and sampled continuous distributions H=(P,DIM,COND,ARG,STEP)</span>
0003 <span class="comment">%</span>
0004 <span class="comment">%  Inputs:  P        is a vector or matrix of probabilities - one dimension per variable</span>
0005 <span class="comment">%           DIM      lists dimensions along which to evaluate the v_entropy [default: 1st non singleton dimension]</span>
0006 <span class="comment">%           COND     lists dimensions to use as conditional variables [default - none]</span>
0007 <span class="comment">%           ARG      lists dimensions to use as parameters in the ouput [default - none]</span>
0008 <span class="comment">%           STEP     for continuous distributions STEP gives the sample increment for each dimension of P</span>
0009 <span class="comment">%                    if STEP is a scalar, the increment is assumed to be the same for each dimension</span>
0010 <span class="comment">%</span>
0011 <span class="comment">% Outputs:  H        is the v_entropy. It will have the same number of dimensions as the length of the ARG input.</span>
0012 <span class="comment">%                    If the STEP argument is specified then this will be the differential v_entropy.</span>
0013 <span class="comment">%</span>
0014 <span class="comment">% Example: Suppose P(W,X,Y,Z) represents the joint probability of four correlated random variables</span>
0015 <span class="comment">%</span>
0016 <span class="comment">%               (a) H(W,X,Y,Z) = v_entropy(P,[1 2 3 4]).</span>
0017 <span class="comment">%               (b) H(W) = v_entropy(P), or equivalently v_entropy(P,1)</span>
0018 <span class="comment">%               (c) H(W,Z | X,Y) = v_entropy(P,[1 4],[2 3])</span>
0019 <span class="comment">%               (d) H(W | X, Z=z) = v_entropy(P,1,2,4); this is a function of z and will be a column vector</span>
0020 <span class="comment">%</span>
0021 <span class="comment">% As a special case, if the dimensions included in DIM are all singletons, the entries in P are treated</span>
0022 <span class="comment">% as Bernoulli variable probabilities.</span>
0023 
0024 <span class="comment">%       Copyright (C) Mike Brookes 2006</span>
0025 <span class="comment">%      Version: $Id: v_entropy.m 10865 2018-09-21 17:22:45Z dmb $</span>
0026 <span class="comment">%</span>
0027 <span class="comment">%   VOICEBOX is a MATLAB toolbox for speech processing.</span>
0028 <span class="comment">%   Home page: http://www.ee.ic.ac.uk/hp/staff/dmb/voicebox/voicebox.html</span>
0029 <span class="comment">%</span>
0030 <span class="comment">%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%</span>
0031 <span class="comment">%   This program is free software; you can redistribute it and/or modify</span>
0032 <span class="comment">%   it under the terms of the GNU General Public License as published by</span>
0033 <span class="comment">%   the Free Software Foundation; either version 2 of the License, or</span>
0034 <span class="comment">%   (at your option) any later version.</span>
0035 <span class="comment">%</span>
0036 <span class="comment">%   This program is distributed in the hope that it will be useful,</span>
0037 <span class="comment">%   but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
0038 <span class="comment">%   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
0039 <span class="comment">%   GNU General Public License for more details.</span>
0040 <span class="comment">%</span>
0041 <span class="comment">%   You can obtain a copy of the GNU General Public License from</span>
0042 <span class="comment">%   http://www.gnu.org/copyleft/gpl.html or by writing to</span>
0043 <span class="comment">%   Free Software Foundation, Inc.,675 Mass Ave, Cambridge, MA 02139, USA.</span>
0044 <span class="comment">%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%</span>
0045 
0046 <span class="keyword">if</span> nargin&lt;5
0047     stp=zeros(ndims(p),1);
0048 <span class="keyword">else</span>
0049     stp=repmat(step(1),ndims(p),1);
0050     stp(1:length(step))=step(:);
0051     stp=log2(stp);
0052 <span class="keyword">end</span>
0053 <span class="keyword">if</span> nargin&lt;4
0054     arg=[];
0055 <span class="keyword">else</span>
0056     arg=arg(arg&gt;0);
0057 <span class="keyword">end</span>
0058 <span class="keyword">if</span> nargin&lt;3
0059     cond=[];
0060 <span class="keyword">else</span>
0061     cond=cond(cond&gt;0);
0062 <span class="keyword">end</span>
0063 <span class="keyword">if</span> ~length(cond)
0064     s=size(p);
0065     <span class="keyword">if</span> nargin&lt;2
0066         dim=find(s&gt;=min(2,max(s)));
0067         dim=dim(1);
0068     <span class="keyword">else</span>
0069         dim=dim(dim&gt;0);
0070     <span class="keyword">end</span>
0071     st=prod(s);
0072     sd=prod(s(dim));
0073     sa=prod(s(arg));
0074     marg=1:length(s);
0075     marg(arg)=0;
0076     marg(dim)=0;
0077     marg=marg(marg&gt;0);
0078     sm=st/sd/sa;
0079     <span class="keyword">if</span> sm&gt;1
0080         ip=[arg dim(:)' marg(:)'];
0081         sp=[s([arg dim(:)']) prod(s(marg))];
0082         q=sum(reshape(permute(p,[arg(:)' dim(:)' marg]),sa,sd,sm),3);
0083     <span class="keyword">else</span>
0084         q=reshape(permute(p,[arg(:)' dim(:)' marg]),sa,sd);
0085     <span class="keyword">end</span>
0086     <span class="keyword">if</span> sd==1
0087         h=-log2(q+(q==0)).*q-log2(1-q+(q==1)).*(1-q);   <span class="comment">% special treatment for bernoulli variables</span>
0088     <span class="keyword">else</span>
0089         sq=sum(q,2);
0090         h=sum(-log2(q+(q==0)).*q,2)./sq+log2(sq);
0091     <span class="keyword">end</span>
0092     <span class="keyword">if</span> length(arg)&gt;1
0093         h=reshape(h,s(arg));
0094     <span class="keyword">end</span>
0095     h=h+sum(stp(dim));
0096 <span class="keyword">else</span>
0097     <span class="comment">% we could probably make this more efficient by avoiding the recursive call</span>
0098     h=<a href="v_entropy.html" class="code" title="function h=v_entropy(p,dim,cond,arg,step)">v_entropy</a>(p,[dim(:); cond(:)],0,arg)-<a href="v_entropy.html" class="code" title="function h=v_entropy(p,dim,cond,arg,step)">v_entropy</a>(p,cond,0,arg);
0099 <span class="keyword">end</span></pre></div>
<hr><address>Generated by <strong><a href="http://www.artefact.tk/software/matlab/m2html/">m2html</a></strong> &copy; 2003</address>
</body>
</html>